|
ExitThread ends a thread.
Syntax
VOID ExitThread(
DWORD ExitCode
);
Parameters
ExitCode
The exit code for the calling thread. Use GetExitCodeThread to retrieve a thread's exit code.
Return Values
This function does not return a value.
Remarks
ExitThread is the preferred method of exiting a thread. When this function is called (either explicitly or by returning from a thread procedure), the current thread's stack is de-allocated and the thread terminates.
If the thread is the last thread in the process when this function is called, the thread's process is also terminated.
Terminating a thread does not necessarily remove the thread object from the operating system. A thread object is deleted when the last handle to the thread is closed.
ExitProcess, ExitThread, CreateThread, and a process that is starting are serialized between each other within a process. Only one of these events can occur at a time.
If the primary thread calls ExitThread, the application will exit.
A small memory leak (approximately 1040 bytes per thread) occurs in the C Runtime library when CreateThread and ExitThread are used instead of _beginthreadex and _endthreadex to create and terminate real-time threads. For more information, see the Microsoft support article at https://support.microsoft.com/en-us/kb/104641. Note that the Stack space for a real-time thread is not freed until all handles to the thread have been closed.
Requirements
Library | Rtx_Rtss.lib |
See Also: